<div class="container-fluid notsel">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
			
                        <ol class="breadcrumb" style="margin-top:8px;position:relative;margin-bottom:5px;">
                            <li>
                                <i class="fa fa-truck"></i>  菜单管理
                            </li>
                            <li class="active">菜式管理
                            </li>
                            <li class="active">编辑菜式
                            </li>  
                           <div style="position:absolute;right:2%;top:23%;cursor:pointer;">
                			<i class="fa fa-arrow-circle-left fa-lg"   onclick="window.location.href='/cuisine/init'"></i> 
                		</div>                          
                        </ol>
                    </div>
                </div>
                <form method="post" action="/adddingredient">
                
                <div class="row">
					<div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <form role="form">
          								 
          								<div class="form-group">
                     <div class="table-responsive" >
                     	                        <div class="form-group">
                                            <label>菜式名称</label>
                                            <input class="form-control" name="cuisinename" id="cuisinename" value="<%=cuisines.name %>">
                                        </div>
                         <table class="table table-hover table-striped" style="margin-bottom:10px;">
                         
                         
                         <tr class="addIngredient">
                         	<td style="font-weight:bold">
                         		点击添加已有材料
                         	</td>
                         	<td align="right">
                         			<i class=" fa fa-chevron-down icon-2x"></i>&nbsp;
                         	</td>
                         </tr>
                        	<tr style="background:#f9f9f9;" class="inputIngWin">
	        <td width="50%"><select class="form-control" name="ingredientType" id="ingredientType" onchange=" filterIng()">
									  
								            </select></td>
            <td width="50%">   	    
                <input type="text" class="form-control" name="ingsx" id="ingsx" value="" placeholder="请输入拼音缩写进行过滤">
    </td>

        </tr>
        <tr style="background:#f9f9f9" class="inputIngWin">
        	  <td  colspan="2">
        	  	<div>
  <% ingredients.forEach(function(ingredient, index) { %>
  <div class="grid-item f_in" style="float:left" sx="<%=ingredient.sx %>"  typeid="<%=ingredient.type._id %>" ingId="<%=ingredient._id %>" ingName="<%=ingredient.name %>" ingPrice="<%=ingredient.pricerecords.length>0?ingredient.pricerecords[ingredient.pricerecords.length-1].price:0%>"   ingUnit="<%=ingredient.pricerecords.length>0?ingredient.pricerecords[ingredient.pricerecords.length-1].unit:"斤"%>"><%=ingredient.name %> </div>
<%}) %>     
</div>
        	  </td>
        
        </tr>
        <tr style="background:#f9f9f9;">
        	<td colspan="2">
        		<table class="table table-hover" id="cart" >
        			 <thead>
                                    <tr>
                                   		<th width="20%">名称</th>
                                        <th width="20%">数量</th>
                                        <th width="20%">单价</th>
                                        <th width="20%">总价(元)</th>
                                        <th width="20%"> </th>
                                    </tr>
                                  		
                                  	<tr class="counttr">
                                   		<td style="font-weight:bold;">合计：</td><td colspan="2" ></td>
                                   		<td id="totalcount">0</td><td></td>
                                        
                                    </tr>	
                                  		
                                     <tr class="addtr">
                                   		<td colspan="5"><input type="text"  id="ingaddname" />&nbsp;&nbsp;<i class="fa  fa-plus-circle"  style="cursor:pointer;" onclick=" addOtherItem()"></i></td>
                                        
                                    </tr>
                                    
                                </thead>
        		</table>
        	</td>
        </tr>
        
        </table>
                        </div>
                                        </div>
                
                                       
                   
								          <div align="right">
                                        	<button type="button" class="btn btn-default" onclick="updatePurChase()">保存</button>
                                        	</div>
                                    </form>
                                </div>

                            </div>
                            <!-- /.row (nested) -->
                        </div>
                </div>
                </form>
            </div>
             <script src="/javascripts/masonry.pkgd.min.js"></script>
               <script src="/javascripts/purchase/js/purchase.js"></script>
               <script>
        			 <% cuisines.productionMaterias.forEach(function(productionMateria, index) { %>
        			 	var id="<%= productionMateria.id %>";
        			 	 var obj=$(".grid-item[ingid='"+id+ "']");
        			 	obj.removeClass("f_in");
						obj.addClass("f_in_sel");
        			     var name="<%= productionMateria.name %>";
        			 	 var type="<%= productionMateria.type %>";
        			 	 var gprice="<%= productionMateria.dj %>";
        			 	 var count="<%= productionMateria.sl %>";
        			 	 var gunit="<%= productionMateria.unit==null?"斤":productionMateria.unit %>";
        			 	 addPurchaseItem(id, name, type, gprice, gunit,count);
				<%}) %>   
				
 function updatePurChase() {
 	var id="<%=cuisines._id %>";
	var cuisinename = $("#cuisinename").val();
	var buyItems = [];
	$("#cart .datatr").each(function() {
		var buyItem = {};
		var ingId = $(this).attr("ingId");
		var ingname = $(this).attr("ingname");
		var ingtype = $(this).attr("ingtype");
		var sl = $(this).find(".sl").val();
		var dj = $(this).find(".dj").html();
		var unit = $(this).find(".unit").val();
		buyItem["id"] = ingId;
		buyItem["name"] = ingname;
		buyItem["type"] = ingtype;
		buyItem["sl"] = sl;
		buyItem["dj"] = dj;
		buyItem["zj"] = (sl * dj).toFixed(2);
		buyItem["unit"] = unit;
		buyItems.push(buyItem);
	});
	$.post("/cuisine/update", {
		"cuisinename" : cuisinename,
		"buyItems" : buyItems,
		"price" : $("#totalcount").html(),
		"id":id
	}, function() {
		window.location.href = "/cuisine/init";
	});
}
               </script>
               
